package mblog.core.data.xml;

import mblog.core.persist.entity.PostPO;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

/**
 * Project  : mblog
 * Author   : Wu Tian Qiang
 * Date     : 2016/7/21
 */
@XmlRootElement(name = "urlset")
public class SiteMap {
    private String xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9";
    private List<URL> urlset = new ArrayList<>();

    public SiteMap() {
    }

    public SiteMap(List<PostPO> postPOs) {
        for (PostPO p : postPOs) {
            URL url = new URL(p.getId());
            urlset.add(url);
        }
    }

    @XmlAttribute
    public String getXmlns() {
        return xmlns;
    }

    public void setXmlns(String xmlns) {
        this.xmlns = xmlns;
    }

    @XmlElements({
            @XmlElement(name = "url", type = URL.class)
    })
    public List<URL> getUrlset() {
        return urlset;
    }

    public void setUrlset(List<URL> urlset) {
        this.urlset = urlset;
    }
}
